<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="css/Tree.css" />
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css" />
<table class="display" id="example">
	<thead>
		<tr>
			<th>选择</th>
			<th>培训课程</th>
			<th>开始日期</th>
			<th>结束日期</th>
			<th>培训对象</th>
			<th>培训类型</th>
			<th>地点</th>
			<th>讲师</th>
			<th>讲师类别</th>
			<th>课程讲义</th>
			<th>操作</th>
		</tr>
	</thead>
	<tbody>
		<s:if test="#request.plans==null || #request.plans.size<=0">
			<tr class="gradeA">
				<td colspan="11">暂无数据</td>
			</tr>
		</s:if>
		<s:else>
			<s:iterator var="plan" status="sta" value="#request.plans">
				<s:if test="#sta.even">
					<tr class="gradeA">
				</s:if>
				<s:else>
					<tr class="gradeC">
				</s:else>
				<td><input type="checkbox" name="chk_plan" value="${plan.id}" /></td>
				<td>${plan.title}</td>
				<td><fmt:formatDate value="${plan.planStartDate}" pattern="yyyy-MM-dd HH:mm"/></td>
				<td><fmt:formatDate value="${plan.planEndDate}" pattern="yyyy-MM-dd HH:mm"/></td>
				<td><span name="td_dutytarget" title="${plan.id}"></span></td>
				<td>${plan.category}</td>
				<td>${plan.classroom}</td>
				<td>${plan.trainLecturer.employeeinfoWork.baseId.name}</td>
				<td>内聘</td>
				<td class="gradeX"><a class="button"
					href="#train/materresource_manage_main.xhtml?planId=${plan.id}&organizationId=${plan.organization.id}"><span
						style="background: url(images/img/page_save.png)"
						class="icon icon-ok">&nbsp;</span>下载</a></td>
				<td><a class="button"
					href="#train/plan_manage.xhtml?planId=${plan.id}&p=f"><span
						style="background: url(${ctx}/images/img/page_edit.png)"
						class="icon">&nbsp;</span>修改</a></td>
				</tr>
			</s:iterator>
		</s:else>
	</tbody>
</table>
<p>
	<%@ include file="/WEB-INF/pages/common/main_orgtab_pager_train.jsp"%>
</p>
<div class="tabs side grid_12 leading">
	<div class="clear"></div>
	<div class="grid_12">
		<div class="form-action clearfix">
			<p>
				<input type="checkbox" value="1" id="form-updates-i2"
					onchange="checkAll(this,'chk_plan')" /><label
					for="form-updates-i2">全选</label> <a class="button"
					href="javascript:void(0)" onclick="deleteDatas('chk_plan')"><span
					style="background: url(${ctx}/images/img/cancel.png)" class="icon">&nbsp;</span>批量删除</a>
				<a class="button"
					href="#train/plan_manage.xhtml?organizationId=${organizationId}&p=f"><span
					style="background: url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>添加</a>
			</p>
		</div>
	</div>
</div>
<div class="clear"></div>

<script type="text/javascript">	
	/**
	* 删除数据
	*/
	function deleteDatas(name) {
		var checkIds = new Array();
		$("input[type='checkbox'][name='" + name + "']").each(function() {
			if (this.checked) {
				checkIds.push(this.value);
			}
		});
		if (checkIds.length == 0) {
			return;
		}
		if (confirm("确定要删除选中的数据吗？")) {
			doDeleteDatas("${ctx}/train/plan_delete.xhtml",checkIds.join(","));
		}
	}
	
	/**
	 * 删除指定数据集
	 * @param url
	 * @param ids
	 */
	function doDeleteDatas(url,ids) {
		$.ajax({
			type : "get",
			url : url,
			data: {"ids":ids},
			dataType : "json",
			success : function(data) {
				// load the grade list
				//currentTabOrgId
				if(typeof(currentTabOrgId) == 'number'){
					loadListContent("${ctx}${listAction}", currentTabOrgId);
				}else{
					loadListContent("${ctx}${listAction}",${organizationId});
				}
			}
		});
	}
	
	$(document).ready(function() {
		$("span[name='td_dutytarget']").each(function(i) {
			loadDutyTarget(this, $(this).attr("title"));
		});
	});

	function loadDutyTarget(obj, planId) {
		$.ajax({
			type : "get",
			url : "/ajax/query_dutytarget.xhtml?planId=" + planId,
			//data: "name=John&location=Boston",
			dataType : "html",
			success : function(data) {
				if (data != null) {
					$(obj).html(data);
				}
			}
		});
	}
	
</script>